package com.example.function.sys.dao.one;


import com.example.common.dao.BaseJpaRepository;
import com.example.function.sys.model.one.SysUser;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

public interface SysUserJpaRepository extends BaseJpaRepository<SysUser, Long> {
    /**
     * 根据用户登录名称和用户类型获取用户信息
     */
    public SysUser findSysUserByUserLoginNameAndUserType(String loginName, Integer userType);

    /**
     * 根据用户登录名称获取用户信息
     */
    public SysUser findSysUserByUserLoginName(String loginName);


    /**
     * 根据用户id查询用户权限
    */
    @Query(value = "select t.role_id as id,t.role_name as roleName from tbl_sys_role t,tbl_sys_userrole s where t.role_id = s.usro_roleid_fk and s.usro_userid_fk = :userId", nativeQuery = true)
    public List<Map> findRoleByUserId(@Param("userId") Long userId);


    /**
     * 根据部门ID查询用户列表
    */
    //@Query(value = "select s.sys_user_id as id,s.sys_user_login_name as userLoginName,s.sys_user_name as userName from tbl_sys_user s where s.sys_user_depart_id_fk = :departmentId", nativeQuery = true)
    public List<SysUser> findSysUsersByUserDepartId(Long departmentId);
}
